package com.jt.controller;/**
 * @Author 金帮嘉诚 @Date 2021-07-29 星期四 16:30
 */
/*本类用于测试*/

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识点
 */
@RestController
@CrossOrigin
@RequestMapping("/axios/")
public class AxiosController {
    @Autowired
    private UserService userService;

//    @GetMapping("user")
//    public List<User> getUserList() {
//        return userService.getALl();
//    }

//    @GetMapping("user/{id}")
//    public User getUserById(@PathVariable Integer id) {
//        return userService.getUserById(id);
//    }
//
//    @GetMapping("user/{name}/{age}")
//    public List<User> getUserByUser(User user){
//        return userService.getUserByUser(user);
//    }

    @GetMapping("getId")
    public String getId(Integer id) {
        System.out.println(id);
        return "AXIOS的ID查询:"+id;
    }


    @GetMapping("user")
    public List<User> getUser1(User user) {
        System.out.println(user);
        return userService.getUserByUser(user);
    }

    /*测试*/
    @PostMapping("user1")
    public User addUser1(@RequestBody User user) {
        return user;
    }

    @PostMapping("user")
    /**
     * @ResponseBody 对象转化为Json
     * @RequestBody Json串转化为对象
     * */
    public int addUser(@RequestBody User user) {
        return userService.add(user);
    }

    @PostMapping("user/{name}/{age}/{sex}")
    //不写@RequestBody注解才能识别
    public int addUser2(User user) {
        return userService.add(user);
    }

}
